package org.jeecg.util;

import org.apache.commons.lang.time.DateFormatUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

/**
*
* <p>Title: DateTimeUtil </p>
* <p>Description: DateTimeUtil</p>
* <p>Copyright: Copyright (c) 2013-9-22</p>
* <p>Company:</p>
* @author
* @version 1.0
* @Comment 日期公用类
*/

public class DateTimeUtil {

	//格式：2007年06月07日 12时12分12秒234毫秒
	private final static String[] FORMAT_CHINA = {"年","月","日","时","分","秒","毫秒"};
	//格式：2007年06月07日
	private final static String[] FORMAT_DATE_CHINA = {"年","月","日"};
	//格式：2007-06-07  12:12:12 234
	private final static String[] FORMAT_NORMAL = {"-","-","",":",":","",""};
	//格式：2007/06/07 12:12:12 234
	private final static String[] FORMAT_DATATIME = {"/","/","",":",":","",""};
	//格式：中文星期
	private final static String[] FORMAT_WEEK = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

	/**
	 * 获取上月信息
	 * @Title: getLastMonth
	 * @Description: TODO
	 * @Param: @param formart 给定转换格式
	 * @Param: @return
	 * @Return: String
	 * @Comment:
	 * @Author: Administrator
	 * @CreateDate: Mar 29, 2012 8:54:59 PM
	 */
	public static String getLastMonth(String strFormart){
		SimpleDateFormat df = new SimpleDateFormat(strFormart);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.MONTH, -1);
		return df.format(calendar.getTime()).toString();
	}
	/**
	 * 获取自定义的制定月份时间
	 * @param month
	 * @param strFormart
	 * @return
	 */
	public static String getCustomMonth(int month,String strFormart){
		SimpleDateFormat df = new SimpleDateFormat(strFormart);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.MONTH, month);
		return df.format(calendar.getTime()).toString();
	}


	/**
	 * 获取今日年份
	 * @return yyyy
	 */
	public static String getTodayYear(){
		return DateFormatUtils.format(new Date(), "yyyy");
	}

	/**
	 * 获取今日月份
	 * @return MM
	 */
	public static String getTodayMonth(){
		return DateFormatUtils.format(new Date(), "MM");
	}
	/**
	 * 获取上月信息 以yyyymm格式返回
	 * @Title: getLastMonthChar6
	 * @Description: TODO
	 * @Param: @return
	 * @Return: String
	 * @Comment:
	 * @Author: Administrator
	 * @CreateDate: 2012-6-9 下午03:37:12
	 */
	public static String getLastMonthChar6(){
		GregorianCalendar gerCal = new GregorianCalendar();
		gerCal.setTime(new Date());
		gerCal.add(GregorianCalendar.MONTH, -1);// 在日期上减1天
		SimpleDateFormat lastDf = new SimpleDateFormat("yyyyMM");
		return lastDf.format(gerCal.getTime()).toString();
	}

	/**
	 * 获取今日日期
	 * @return dd
	 */
	public static String getTodayDay(){
		return DateFormatUtils.format(new Date(), "dd");
	}

	/**
	 * 获取短日月
	 * @return MMdd
	 */
	public static String getTodayChar4(){
		return DateFormatUtils.format(new Date(), "MMdd");
	}

	/**
	 * 获取短日月
	 * @return MMdd
	 */
	public static String getTodayChar4En(){
		return DateFormatUtils.format(new Date(), "MM-dd");
	}

	/**
	 * 返回年月
	 * @return yyyyMM
	 */
	public static String getTodayChar6(){
		return DateFormatUtils.format(new Date(), "yyyyMM");
	}

	/**
	 * 返回年月
	 * @return yyyyMM
	 */
	public static String getTodayChar6En(){
		return DateFormatUtils.format(new Date(), "yyyy-MM");
	}

	/**
	 * 返回年月日
	 * @return yyyyMMdd
	 */
	public static String getTodayChar8(){
		return DateFormatUtils.format(new Date(), "yyyyMMdd");
	}

	/**
	 * 返回年月日
	 * @return yyyyMMdd
	 */
	public static String getTodayChar8En(){
		return DateFormatUtils.format(new Date(), "yyyy-MM-dd");
	}
	/**
	 * 获取昨天日期 格式 yyyy-MM-dd
	 * @Title: getLastDayChar8En
	 * @Description: TODO
	 * @Param: @return
	 * @Return: String
	 * @Comment:
	 * @Author: Administrator
	 * @CreateDate: 2012-5-29 上午11:20:37
	 */
	public static String getLastDayChar8En(){
		GregorianCalendar gerCal = new GregorianCalendar();
		gerCal.setTime(new Date());
		gerCal.add(GregorianCalendar.DATE, -1);// 在日期上减1天
		SimpleDateFormat lastDf = new SimpleDateFormat("yyyy-MM-dd");
		return lastDf.format(gerCal.getTime());
	}


	public static String getLastDayCharN8En(Integer n){
		GregorianCalendar gerCal = new GregorianCalendar();
		gerCal.setTime(new Date());
		gerCal.add(GregorianCalendar.DATE, -n);// 在日期上减1天
		SimpleDateFormat lastDf = new SimpleDateFormat("yyyy-MM-dd");
		return lastDf.format(gerCal.getTime());
	}

	public static String getLastDayChar8Cn(){
		GregorianCalendar gerCal = new GregorianCalendar();
		gerCal.setTime(new Date());
		gerCal.add(GregorianCalendar.DATE, -1);// 在日期上减1天
		SimpleDateFormat lastDf = new SimpleDateFormat("yyyyMMdd");
		return lastDf.format(gerCal.getTime());
	}
	/**
	 * 获取当前时间距离当天凌晨的时长
	 * @return
	 */
	public static long getNextDayToCurrentTimes(){
		GregorianCalendar gerCal = new GregorianCalendar();
		gerCal.setTime(new Date());
		gerCal.add(GregorianCalendar.DATE, 1);
		SimpleDateFormat lastDf = new SimpleDateFormat("yyyyMMdd");
		String nextDay = lastDf.format(gerCal.getTime());
		Date date = null;
		try {
			date = lastDf.parse(nextDay);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		long countdown =date.getTime() - System.currentTimeMillis();
		return countdown;
	}

	/**
	 * 返回 年月日小时分
	 * @return yyyyMMddHHmm
	 */
	public static String getTodayChar12() {
		return DateFormatUtils.format(new Date(),"yyyyMMddHHmm");
	}

	/**
	 * 返回 年月日小时分
	 * @return yyyyMMddHHmm
	 */
	public static String getTodayChar12En() {
		return DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm");
	}

	/**
	 * 返回 2位年月日小时分
	 * @return yyMMddHHmmss
	 */
	public static String getTodayChar12Short() {
		return DateFormatUtils.format(new Date(),"yyMMddHHmmss");
	}

	/**
	 * 返回 年月日小时分秒
	 * @return
	 */
	public static String getTodayChar14(){
		return DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
	}

	/**
	 * 返回 年月日小时分秒
	 * @return
	 */
	public static String getTodayChar14En(){
		return DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
	}


	/**
	 * 返回 年月日小时分秒 毫秒
	 * @return
	 */
	public static String getTodayChar17(){
		return DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS");
	}
	/**
	 * 返回 年月日小时分秒 毫秒
	 * @return
	 */
	public static String getTodayChar17En(){
		return DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss SSS");
	}

	/**
	 * 返回 年月日小时分秒 毫秒
	 * @return
	 */
	public static String getToDateCn(){
		return DateFormatUtils.format(new Date(), "yyyy年MM月dd日");
	}



	/**
	 * 返回 年-月-日
	 * @return
	 */
	public static String getToDateEn(){
		return DateFormatUtils.format(new Date(), "yyyy-MM-dd");
	}



	/**
	 * 返回中文日期格式 支持4、6、8、12、14、17位转换
	 * @param charDateTime 长整型 CHAR
	 * @return 2007年12月12日 12时12分12秒 234毫秒
	 */
	public static String getFormatChina(String charDateTime){
		return getFormatDateTime(charDateTime,"FORMAT_CHINA");
	}



	/**
	 * 返回标准日期格式 支持4、6、8、12、14、17位转换
	 * @param charDateTime 长整型 CHAR
	 * @return  2007-12-12 12:12:12 234
	 */
	public static String getFormatNormal(String charDateTime){
		return getFormatDateTime(charDateTime,"FORMAT_NORMAL");
	}


	/**
	 * 返回标准日期格式 支持4、6、8、12、14、17位转换
	 * @param charDateTime 长整型 CHAR
	 * @return  2007/12/12 12:12:12 234
	 */
	public static String getFormatDateTime(String charDateTime){
		return getFormatDateTime(charDateTime,"FORMAT_DATATIME");
	}

	/**
	 * 把日期格式转换为长整型格式
	 * @param inputDateTime
	 * @return
	 */
	public static String getDateTimeToChar(String inputDateTime){
		String strResult="";
		if( null == inputDateTime ){
			return strResult="";
		}

		if(("".equals(inputDateTime.trim()))){
			return strResult="";
		}

		//替换
		strResult=inputDateTime.replaceAll("年", "");
		strResult=strResult.replaceAll("月", "");
		strResult=strResult.replaceAll("日", "");
		strResult=strResult.replaceAll("时", "");
		strResult=strResult.replaceAll("分", "");
		strResult=strResult.replaceAll("秒", "");
		strResult=strResult.replaceAll("毫", "");
		strResult=strResult.replaceAll(" ", "");
		strResult=strResult.replaceAll("-", "");
		strResult=strResult.replaceAll("/", "");
		strResult=strResult.replaceAll(":", "");
		return strResult;

	}

	/**
	 * 对日期进行转换
	 * @Title: getFormatDateTime
	 * @Description: TODO
	 * @Param: @param charDateTime
	 * @Param: @param formatType  FORMAT_CHINA 中文 FORMAT_NORMAL以‘-’先分隔 FORMAT_DATATIME 以‘/’分隔
	 * @Param: @return
	 * @Return: String
	 * @Comment:
	 * @Author: Administrator
	 * @CreateDate: Mar 29, 2012 8:35:29 PM
	 */
	private static String getFormatDateTime(String charDateTime,String formatType){
		String strResult="";
		if( null == charDateTime ){
			return strResult="";
		}

		if(("".equals(charDateTime.trim()))){
			return strResult="";
		}

		String[] FORMAT_CHAR=null;
		if(formatType.equals("FORMAT_CHINA")){
			FORMAT_CHAR = FORMAT_CHINA;
		}else if(formatType.equals("FORMAT_NORMAL")){
			FORMAT_CHAR = FORMAT_NORMAL;
		}else if(formatType.equals("FORMAT_DATATIME")){
			FORMAT_CHAR = FORMAT_DATATIME;
		}else{
			return strResult=charDateTime;
		}

		//去掉空格
		charDateTime = charDateTime.trim();

		if(charDateTime.length()== 4 ){
			//MMdd 转换 MM月dd日
			strResult=charDateTime.substring(0, 2) + FORMAT_CHAR[1]
		   		    + charDateTime.substring(2, 4) + FORMAT_CHAR[2];
		}else if (charDateTime.length()== 6 ){
			//yyyyMM 转换 yyyy年MM月
			strResult=charDateTime.substring(0, 4) + FORMAT_CHAR[0]
		   		    + charDateTime.substring(4, 6) + FORMAT_CHAR[1];
		}else if (charDateTime.length()== 8 ){
			//yyyyMMdd
			strResult=charDateTime.substring(0, 4) + FORMAT_CHAR[0]
			        + charDateTime.substring(4, 6) + FORMAT_CHAR[1]
			        + charDateTime.substring(6, 8) + FORMAT_CHAR[2];
		}else if (charDateTime.length()== 12 ){
			//yyyyMMddHHmm
			strResult=charDateTime.substring(0, 4) + FORMAT_CHAR[0]
			        + charDateTime.substring(4, 6) + FORMAT_CHAR[1]
			        + charDateTime.substring(6, 8) + FORMAT_CHAR[2]
			        + " "
			        + charDateTime.substring(8, 10) + FORMAT_CHAR[3]
			        + charDateTime.substring(10, 12) + FORMAT_CHAR[4];
		}else if (charDateTime.length()== 14 ){
			//yyyyMMddHHmmss
			strResult=charDateTime.substring(0, 4) + FORMAT_CHAR[0]
			        + charDateTime.substring(4, 6) + FORMAT_CHAR[1]
			        + charDateTime.substring(6, 8) + FORMAT_CHAR[2]
			        + " "
			        + charDateTime.substring(8, 10) + FORMAT_CHAR[3]
			        + charDateTime.substring(10, 12) + FORMAT_CHAR[4]
			        + charDateTime.substring(12, 14) + FORMAT_CHAR[5];
		}else if (charDateTime.length()== 17 ){
			//yyyyMMddHHmmssS
			strResult=charDateTime.substring(0, 4) + FORMAT_CHAR[0]
			        + charDateTime.substring(4, 6) + FORMAT_CHAR[1]
			        + charDateTime.substring(6, 8) + FORMAT_CHAR[2]
			        + " "
			        + charDateTime.substring(8, 10) + FORMAT_CHAR[3]
			        + charDateTime.substring(10, 12) + FORMAT_CHAR[4]
			        + charDateTime.substring(12, 14) + FORMAT_CHAR[5]
					+ " "
			        + charDateTime.substring(14, 17) + FORMAT_CHAR[6];
		}else{
			strResult = charDateTime;
		}

		return strResult;
	}

	/**
	 * 将指定Date类型参数转换为指定的Oracle日期时间格式字符串
	 * @param inputDate 传入Date类型参数
	 * @return String
	 */
	public static String getOracleDate(Date inputDateTime)
			throws NullPointerException {
		if (null == inputDateTime) {
			return "";
		}
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		return dateFormat.format(inputDateTime);
	}

	/**
	 * 比对两个时间间隔
	 * @param startDateTime 开始时间
	 * @param endDateTime 结束时间
	 * @param distanceType 计算间隔类型 天d 小时h 分钟m 秒s
	 * @return
	 */
    public static String getDistanceDT(String startDateTime,String endDateTime,String distanceType){
        String strResult="";
        long lngDistancVal=0;
        try{
            SimpleDateFormat tempDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            Date startDate=tempDateFormat.parse(startDateTime);
            Date endDate=tempDateFormat.parse(endDateTime);
            if(distanceType.equals("d")){
            	lngDistancVal = (endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24);
            }else if(distanceType.equals("h")){
            	lngDistancVal = (endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60);
            }else if(distanceType.equals("m")){
            	lngDistancVal = (endDate.getTime() - startDate.getTime()) / (1000 * 60);
            }else if(distanceType.equals("s")){
            	lngDistancVal = (endDate.getTime() - startDate.getTime()) / (1000);
            }
            strResult=String.valueOf(lngDistancVal);
        }catch(Exception e){
        	strResult="0";
        }
        return strResult;
    }



    /**
     * 日期差计算 例如在某个日期增加几天后的日期 返回几天后日期
     * @param startDate
     * @param addDate
     * @return
     */
    public static String getIncreaseDT (String startDate ,int addDate){
        String strResult="0000-00-00";

        try{
            Calendar localDate =new GregorianCalendar();
           //把字符串型日期转换为日期
            Date tempDate = new Date();
        	if(!"".equals(startDate)){
                SimpleDateFormat tempDateFormat = new SimpleDateFormat("yyyyMMdd");
                tempDate=tempDateFormat.parse(startDate);
        	}
            localDate.setTime(tempDate);
            localDate.add(Calendar.DATE,addDate);
            String curyear=""+localDate.get(Calendar.YEAR);
            int intmonth=localDate.get(Calendar.MONTH)+1;
            String curmonth=""+intmonth;
            String curday=""+localDate.get(Calendar.DAY_OF_MONTH);

            if (curmonth.length()==1){
                curmonth="0"+curmonth;
            }
            if (curday.length()==1){
                curday="0"+curday;
            }
            strResult=curyear+""+curmonth+""+curday;
         }catch(Exception e){
        	strResult="";
         }
          return strResult;
      }


    /**
     * 获取本周的开始日期 （星期天的日期）20070201
     * @return
     */
    public static String getWeekStartDate(){
        String strResult="19000101";
        try{
            Calendar calendar = Calendar.getInstance();
            int intWeekNum = calendar.get(Calendar.DAY_OF_WEEK);
            intWeekNum=intWeekNum-1;
            strResult = getIncreaseDT(getTodayChar8(),-intWeekNum);
        }catch(Exception ex){
        	strResult="19000101";
        }
         return strResult;
     }


   /**
    * 获取今天星期几 中文
    * @return
    */
    public static String getWeekChina(){
        String strResult = " ";
        try {
            Calendar calendar = Calendar.getInstance();
            int intWeekNum = calendar.get(Calendar.DAY_OF_WEEK);
            intWeekNum = intWeekNum - 1;
            strResult = FORMAT_WEEK[intWeekNum] ;
        } catch (Exception ex) {
        	strResult = " ";
        }
        return strResult;
    }


    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    private static SimpleDateFormat dateFormat_1 = new SimpleDateFormat("yyyyMM");
    private static SimpleDateFormat dateFormat_2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static SimpleDateFormat dateFormat_3 = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat dateFormat_4 = new SimpleDateFormat("yyyy年MM月");
    private static SimpleDateFormat dateFormat_5 = new SimpleDateFormat("yyyy年MM月dd日");
    private static SimpleDateFormat dateFormat_6 = new SimpleDateFormat("yyyyMMdd");
    private static SimpleDateFormat dateFormat_7 = new SimpleDateFormat("yyyyMMddHHmmss");

	private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
	private static final DateTimeFormatter WEIBO_INPUT_FORMATTER = DateTimeFormatter
			.ofPattern("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);

	// 系统默认时区（避免多次查询）
	private static final ZoneId DEFAULT_ZONE = ZoneId.systemDefault();

    public static String formatDateStrToOtherStr(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_2.format(dateFormat.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}

    public static String formatDateStrToOtherStr3(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_3.format(dateFormat.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}


    public static String formatDateStrToOtherStr4(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_4.format(dateFormat_1.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}

    public static String formatDateStrToOtherStr5(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_5.format(dateFormat_6.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}

    public static String formatDateStrToOtherStr6(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_5.format(dateFormat_7.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}
    public static String formatDateStrToOtherStr8(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_6.format(dateFormat_6.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}
    /**
     * 将 "2012-5-1" 转换成 "20120501"
     * @Title: formatDateStrToOtherStr9
     * @Description: TODO
     * @Param: @param time
     * @Param: @return
     * @Return: String
     * @Comment:
     * @Author: Administrator
     * @CreateDate: Apr 24, 2012 10:09:38 AM
     */
    public static String formatDateStrToOtherStr9(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_6.format(dateFormat_3.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}
    /**
     * 将 "20120501" 转换成  "2012-5-1"
     * @Title: formatDateStrToOtherStr10
     * @Description: TODO
     * @Param: @param time
     * @Param: @return
     * @Return: String
     * @Comment:
     * @Author: Administrator
     * @CreateDate: Apr 29, 2012 3:45:54 PM
     */
    public static String formatDateStrToOtherStr10(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_3.format(dateFormat_6.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}

    /**
     * 返回yyyymmddhhmmss 时间戳
     * @param time
     * @return
     */
    public static long formatDateStrToDateTime(String time) {

		long reTime = 0;
		try {
			reTime = dateFormat.parse(time).getTime();
		} catch (ParseException e) {
		}
		return reTime;
	}


    /**
     * 将 yyyy-MM-dd HH:mm:ss 转换成 yyyy-MM-dd
     * @Title: formatDateStrToOtherStr11
     * @Description: TODO
     * @Param: @param time
     * @Param: @return
     * @Return: String
     * @Comment:
     * @Author: Administrator
     * @CreateDate: May 4, 2012 10:52:59 AM
     */
    public static String formatDateStrToOtherStr11(String time) {
		String reTime = "";
		try {
			reTime = dateFormat_3.format(dateFormat_2.parse(time));
		} catch (ParseException e) {
		}
		return reTime;
	}

    public static void main(String[] args) {
    	for(int i=0; i<20000;i++){
    		System.out.println(getTodayChar17En());
    	}

	}


    /**
     * 比较时间与当前时间先后
     * @Title: compareTime
     * @Description: TODO
     * @Param: @param startTime
     * @Param: @return
     * @Return:  1 晚于当前时间 2 与当前时间相等 3 早于当前时间
     * @Comment:
     * @Author: Administrator
     * @CreateDate: Mar 29, 2012 8:34:11 PM
     */
    public static String compareTime(String startTime) {
    	Date date = new Date();
    	startTime = startTime.substring(0, 4) + "-"
    			   +startTime.substring(4, 6) + "-"
    			   +startTime.substring(6, 8);

    	DateFormat df= new SimpleDateFormat("yyyy-MM-dd");
    	Calendar c1=Calendar.getInstance();
    	Calendar c2=Calendar.getInstance();
    	try{
    		c1.setTime(date);
        	c2.setTime(df.parse(startTime));
    	} catch(ParseException e){
        }
    	int result = c1.compareTo(c2);
    	if(result == 0){
    		return "2";
    	} else if(result < 0){
    		return "1";
    	} else {
    		return "3";
    	}
    }

	/**
	 * 获取当前时间戳（格式：yyyyMMddHHmmss）
	 */
	public static String getCurrentTimestamp() {
		return LocalDateTime.now().format(TIMESTAMP_FORMATTER);
	}

	/**
	 * 将秒级时间戳转换为格式化时间
	 *
	 * @param timestamp 秒级时间戳
	 */
	public static String convertTimestampToFormat(long timestamp) {
		Instant instant = Instant.ofEpochSecond(timestamp);
		return instant.atZone(DEFAULT_ZONE)
				.format(TIMESTAMP_FORMATTER);
	}

	/**
	 * 将毫秒级时间戳转换为格式化时间
	 *
	 * @param timestampMillis 毫秒级时间戳
	 */
	public static String convertMillisTimestamp(long timestampMillis) {
		return Instant.ofEpochMilli(timestampMillis)
				.atZone(DEFAULT_ZONE)
				.format(TIMESTAMP_FORMATTER);
	}

	/**
	 * 解析微博时间格式并转换
	 *
	 * @param weiboTime 微博时间字符串（例：Thu Aug 10 18:12:20 +0800 2023）
	 * @return 格式化后的时间（yyyyMMddHHmmss），解析失败返回null
	 */
	public static String formatWeiboTime(String weiboTime) {
		if (weiboTime == null || weiboTime.isEmpty()) {
			return null;
		}

		try {
			// 直接解析为ZonedDateTime（保留时区信息）
			ZonedDateTime zdt = ZonedDateTime.parse(weiboTime, WEIBO_INPUT_FORMATTER);
			return zdt.format(TIMESTAMP_FORMATTER);
		} catch (DateTimeParseException e) {
			// 记录日志或处理异常（实际项目应使用日志框架）
			System.err.println("微博时间解析失败: " + weiboTime);
			return null;
		}
	}

	/**
	 * 将格式化时间字符串转换为时间戳（秒级）
	 *
	 * @param formattedTime 格式化时间（yyyyMMddHHmmss）
	 * @return 秒级时间戳，解析失败返回-1
	 */
	public static long parseToTimestamp(String formattedTime) {
		if (formattedTime == null || formattedTime.length() != 14) {
			return -1;
		}

		try {
			LocalDateTime ldt = LocalDateTime.parse(formattedTime, TIMESTAMP_FORMATTER);
			return ldt.atZone(DEFAULT_ZONE)
					.toEpochSecond();
		} catch (DateTimeParseException e) {
			System.err.println("时间解析失败: " + formattedTime);
			return -1;
		}
	}

}

